/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("SheBei_Inspection",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using iMES.Entity.DomainModels;
using IMES.SheBei.IServices;
using iMES.Core.Filters;
using IMES.SheBei.IRepositories;

namespace IMES.SheBei.Controllers
{
    public partial class SheBei_InspectionController
    {
        private readonly ISheBei_InspectionService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly ISheBei_SpotCheckmaintenancesRepository _inspectionRepository;
        [ActivatorUtilitiesConstructor]
        public SheBei_InspectionController(
            ISheBei_InspectionService service,
            IHttpContextAccessor httpContextAccessor,
            ISheBei_SpotCheckmaintenancesRepository inspectionRepository
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
            _inspectionRepository = inspectionRepository;
        }

        /// <summary>
        /// 定时任务生成点检工单
        /// </summary>
        /// <returns></returns>
        [ApiTask]
        [HttpGet, HttpPost, Route("generateInspectionWorkOrder")]
        public IActionResult GenerateInspectionWorkOrder()
        {
            return Content(_service.CreateInspectionWorkOrder());
        }

        /// <summary>
        /// 工单状态变更
        /// </summary>
        [HttpGet, Route("changeUpdate")]
        public string ChangeUpdate(string ID, string status, string remark)
        {
            SheBei_Inspection workOrder = new SheBei_Inspection()
            {
                ID = new Guid(ID),
                Status = Convert.ToInt32(status),
                Remark = remark
            };
            _inspectionRepository.Update(workOrder, x => new { x.Status, x.ModifyDate, x.Remark }, true);
            return "变更成功";
        }

    }
}
